<template>
  <div class="model-form">
    <el-page-header @back="goBack" content="增加通告">
    </el-page-header>
    <div class="model-content">
      <el-form ref="ruleForm" :rules="rules" :model="form" label-width="160px">
        <el-row :gutter="10">
          <el-col :span="22">
            <el-form-item label="发布人" size="mini" prop="creator">
              <el-input v-model="form.creator" name="creator">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="单人费用" size="mini" prop="money">
              <el-input v-model="form.money" name="money">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="消费价" size="mini" prop="salePrice">
              <el-input v-model="form.salePrice" name="salePrice">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="招人数" size="mini" prop="amount">
              <el-input v-model="form.amount" name="amount">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="人员性别" size="mini" prop="sex">
              <nb-select catalog="sex" v-model="form.sex"></nb-select>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <div style="margin-left: 160px;">
              <vue-ueditor-wrap v-model="form.note" :config="config" ref="note"></vue-ueditor-wrap>
            </div>

          </el-col>
          <el-col :span="22">
            <el-form-item label="群二维码" size="mini" prop="qrCode">
              <avatar v-model="form.qrCode"></avatar>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="通告类型" size="mini" prop="topicType">
              <el-input v-model="form.topicType" name="topicType">
              </el-input>
            </el-form-item>

          </el-col>

          <el-col :span="22">
            <el-form-item>
              <el-button @click="goBack">取消</el-button>
              <el-button type="primary" @click="add">确定</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
import common from "@/mixins/common.js";
import nbSelect from "@/components/nbSelect.vue";
import VueUeditorWrap from "vue-ueditor-wrap";
import avatar from "@/components/avatar.vue";

export default {
  name: "topic_add",
  mixins: [common],
  components: {nbSelect, VueUeditorWrap, avatar},
  data() {
    return {
      form: {
        creator: '',
        money: '',
        salePrice: '',
        amount: '',
        sex: '',
        note: '',
        qrCode: '',
        topicType: ''
      },
      rules: {
        creator: [
          {required: true, message: '请输入发布人', trigger: 'blur'}
        ],
      }
    }
  },
  methods: {
    async add() {
      let valid = await this.$refs["ruleForm"].validate();
      if (!valid) {
        return false;
      }
      await this.addData();
    },
    async addData() {
      let data = this.form;
      let res = await this.$http.form("/tenantRest/topic/create.htm", data);
      if (res.code !== 0) {
        this.$message.error(res.msg);
      }

      this.$message({
        message: '添加数据成功',
        type: 'success'
      });
      this.$router.go(-1);
    },

  },
  mounted() {
  }
}

</script>

<style scoped>
</style>
